<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>全服物品查询</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>全服物品查询</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" lay-filter="table-search">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">选择区服:</label>
                            <div class="layui-input-inline">
                                <select name="gameArea" class="layui-select">
                                    <option v-for="(item,index) in services" :value="item.server_id" :selected="index==0">{{item.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">物品ID:</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="equipId" placeholder="请输入物品ID"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">物品:</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input layui-disabled" id="equipName" readonly="readonly" placeholder="只读"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">物品唯一ID:</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="equipUuId" placeholder="请输入物品ID" autocomplete="on"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn">
                                <i class="layui-icon"></i> 搜 索</button>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn1">
                                <i class="layui-icon"></i> 全服搜索</button>
                        </div>
                    </div>
                </form>
            </div>

        </fieldset>
        <div style="margin: 10px 10px 10px 10px">
            <button class="layui-btn layui-btn-normal layui-btn-sm" id="exportUuidList">导出重复唯一ID</button>
        </div>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-normal layui-btn-sm " lay-event="export">导出</button>
    </div>
</script>

<script type="text/html" id="currentTableBar">
    <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
</script>

<style>
    .layui-table-cell{
        height: unset !important;
    }
</style>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script>
    new Vue({
        el: "#app",
        data: {
            services: JSON.parse(localStorage.getItem('services')),
        },
        mounted:function () {

            layui.use(['form', 'table'], function () {
                var $ = layui.jquery,
                    form = layui.form,
                    table = layui.table;

                // 监听搜索操作
                form.on('submit(data-search-btn)', function (data) {
                    table.render({
                        where:form.val('table-search'),
                        elem: '#currentTableId',
                        url: '/admin/gameRole/equipSta',
                        toolbar: '#toolbarDemo',
                        defaultToolbar: ['filter', 'exports', 'print' ],
                        cols: [[
                            {type: "checkbox", width: 50},
                            {  title: '区服', width: 100 , templet:function(row){
                                    return row.member?row.member.areaid:'';
                                }},
                            { title: '游戏账号', width: 150, templet:function(row){
                                    return row.member?row.member.username:'';
                                }},
                            {field: 'role_id', width: 300, title: '角色ID' },
                            {field: 'nick', width: 100, title: '角色名' , templet:function(row){
                                    return row.role?row.role.nick:'';
                                }},
                            {field: 'equip_uuid', width: 300, title: '唯一ID' },
                            {field: 'level', width: 100,title: '角色等级'  , templet:function(row){
                                    return row.role?row.role.level:'';
                                }},
                            {title: '物品信息', templet:function(row){
                                return "ID:"+row.equip_id+" 名称:"+(row.equip?row.equip.name:row.equip_id)+" 数量:"+row.count;
                            }}
                        ]],
                        limits: [10, 15, 20, 25, 50, 100],
                        limit: 15,
                        page: true,
                        skin: 'line',
                        done:function (res) {
                            var equip = res.equip;
                            if (equip){
                                $('#equipName').val(equip.name)
                            }
                        }
                    });
                    return false;
                });

                // 监听全服操作
                form.on('submit(data-search-btn1)', function (data) {
                    table.render({
                        where:form.val('table-search'),
                        elem: '#currentTableId',
                        url: '/admin/gameRole/equipStahb',
                        toolbar: '#toolbarDemo',
                        defaultToolbar: ['filter', 'exports', 'print' ],
                        cols: [[
                            {type: "checkbox", width: 50},
                            {  title: '区服', width: 100 , templet:function(row){
                                    return row.member?row.member.areaid:'';
                                }},
                            { title: '游戏账号', width: 150, templet:function(row){
                                    return row.member?row.member.username:'';
                                }},
                            {field: 'role_id', width: 300, title: '角色ID' },
                            {field: 'nick', width: 100, title: '角色名' , templet:function(row){
                                    return row.role?row.role.nick:'';
                                }},
                            {field: 'equip_uuid', width: 300, title: '唯一ID' },
                            {field: 'level', width: 100,title: '角色等级'  , templet:function(row){
                                    return row.role?row.role.level:'';
                                }},
                            {title: '物品信息', templet:function(row){
                                    return "ID:"+row.equip_id+" 名称:"+(row.equip?row.equip.name:row.equip_id)+" 数量:"+row.count;
                                }}
                        ]],
                        limits: [10, 15, 20, 25, 50, 100],
                        limit: 15,
                        page: true,
                        skin: 'line',
                        done:function (res) {
                            var equip = res.equip;
                            if (equip){
                                $('#equipName').val(equip.name)
                            }
                        }
                    });
                    return false;
                });

                /**
                 * toolbar监听事件
                 */
                table.on('toolbar(currentTableFilter)', function (obj) {
                    if (obj.event === 'export') {  // 监听添加操作
                        var searchData = form.val('table-search');
                        searchData.page = 1;
                        searchData.limit = 9999999;
                        asyncDownload(
                            '/admin/gameRole/equipSta/export',
                            searchData,
                            {token:localStorage.getItem('adminToken')}
                        );
                    }
                });

                $('#exportUuidList').click(function () {
                    var searchData = form.val('table-search');

                    asyncDownload(
                        '/admin/gameRole/exportRepeatedUuid',
                        searchData,
                        {token:localStorage.getItem('adminToken')}
                    );
                })

                //监听表格复选框选择
                table.on('checkbox(currentTableFilter)', function (obj) {
                    console.log(obj)
                });

                table.on('tool(currentTableFilter)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'edit') {

                        var index = layer.open({
                            title: '编辑用户',
                            type: 2,
                            shade: 0.2,
                            maxmin:true,
                            shadeClose: true,
                            area: ['100%', '100%'],
                            content: '../page/table/edit.html',
                        });

                        return false;
                    } else if (obj.event === 'delete') {
                        layer.confirm('真的删除行么', function (index) {
                            obj.del();
                            layer.close(index);
                        });
                    }
                });

            });
        }
    })


</script>
</body>
</html>